{% load static %}
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>出货单审核</title>
    <link rel="stylesheet" href="{% static 'plugins/layui/css/layui.css' %}"  media="all">
</head>
<body>
    <div id="examine_failed">
        <div>未通过原因描述：<span style="color: red;"></span></div>
        <textarea rows="10" cols="66" style="margin: 10px" placeholder="请描述未能过原因">
        </textarea>
        <input type="text" value="{{ order_id }}" style="display: none">
        <div class="layui-btn-container" style="text-align: center">
          <button type="button" class="layui-btn layui-btn-primary layui-btn-sm">通 过</button>
          <button type="button" class="layui-btn layui-btn-primary layui-btn-sm">未通过</button>
        </div>
    </div>
    <script src="{% static 'plugins/layui/layui.js' %}" charset="utf-8"></script>
    <script src="{% static 'plugins/jquery-3.4.1.js' %}"></script>
    <script>
        $('.layui-btn-container button').click(function () {
            if ($(this).text() === '通 过') {
                $.ajax({
                    url: '{% url "order_examine" %}',
                    type: 'POST',
                    data: {'examine_result': '通过', 'order_id': $('input[type=text]').val()},
                    dataType: 'JSON',
                    success: function (res) {
                        if (res.status) {
                            parent.layer.closeAll()
                        }else {
                        }
                    }
                })
            }else {
                $.ajax({
                   url: '{% url "order_examine" %}',
                   type: 'POST',
                   data: {'examine_result': '未通过', 'order_id': $('input[type=text]').val(),
                          'failed_desc': $('textarea').val()},
                   dataType: 'JSON',
                   success: function (res) {
                       if (res.status) {
                            parent.layer.closeAll()
                        }else {
                           $('#examine_failed span').text(res.failed_desc)
                        }
                   }
               })
            }
        })

        $('textarea').keyup(function () {
            $('#examine_failed span').text('')
        })
    </script>
</body>
</html>